package com.zy.service.bs.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zy.dao.bs.BalanceDao;
import com.zy.entity.enums.StatusEnum;
import com.zy.entity.bs.Balance;
import com.zy.pojo.query.bs.BalanceQuery;
import com.zy.pojo.vos.common.PageVo;
import com.zy.service.base.impl.BaseServiceImpl;
import com.zy.service.bs.BalanceService;
import com.zy.utils.DateUtil;

@Service("balanceService")
public class BalanceServiceImpl extends BaseServiceImpl<Balance> implements BalanceService {

	@Autowired
	private BalanceDao balanceDao;

	@Override
	public PageVo pageBalance(BalanceQuery balanceQuery, Integer start, Integer limit) {
		return new PageVo(start, limit, this.balanceDao.countBalance(balanceQuery), this.balanceDao.listBalance(balanceQuery, start, limit));
	}

	@Override
	public void saveBalance(Balance balance) {
		long time = DateUtil.getTime();

		this.balanceDao.save(balance);
	}
	
	@Override
	public void updateBalance(Balance balance) {
		this.balanceDao.updateByPrimaryKeySelective(balance);
	}

	@Override
	public void removeBalance(long id) {
		try {
			this.balanceDao.removeByPrimaryKey(id);
		} catch (Exception e) {
			log.info(e.getMessage(),e);
			Balance balance = new Balance();
			balance.setId(id);

			this.balanceDao.updateByPrimaryKeySelective(balance);
		}
	}

	@Override
	public void recover(long id) {
		Balance balance = new Balance();
		balance.setId(id);
		this.balanceDao.updateByPrimaryKeySelective(balance);
	}

}
